package me.zhengjie.inter.service.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.inter.service.MpDictDetailService;
import me.zhengjie.modules.system.repository.DictDetailRepository;
import me.zhengjie.modules.system.service.dto.DictDetailDto;
import me.zhengjie.modules.system.service.mapstruct.DictDetailMapper;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Zheng Jie
 * @date 2022-07-12
 */
@Slf4j
@Service
@RequiredArgsConstructor
@CacheConfig(cacheNames = "dict")
public class MpDictDetailServiceImpl implements MpDictDetailService {

    private final DictDetailRepository dictDetailRepository;
    private final DictDetailMapper dictDetailMapper;

    @Override
  //  @Cacheable(key = "'name:' + #p0")
    public List<DictDetailDto> getDictByName(String name) {
        log.info("移动端[MpDictDetailServiceImpl - getDictByName]查询字典 {} ", name);
        return dictDetailMapper.toDto(dictDetailRepository.findByDictNameOrderByDictSortAsc(name));
    }
}
